<script>
  const soureList = [
    {
      name: 'cp',
      user_id: 1001,
      age: 30
    },
    {
      name: 'dakang',
      user_id: 1002,
      age: 29
    }
  ]
  function toHump(key) {
    return key.replace(/\_(\w)/g, (all, letter) => {
      return letter.toUpperCase()
    })
  }

  function toHump_(str) {
    const arr = str.split('_') // ['user','id','name']
    for (let i = 1; i < arr.length; i++) {
      arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1)
    }
    return arr.join('')
  }


  function transData(souceData) {
    return souceData.map(item => {
      // 准备最后返回的对象
      let obj = {}
      Object.keys(item).forEach(key => {
        if (/\_(\w)/.test(key)) {
          // 如果需要转化 则进行驼峰转化
          let _key = toHump_(key)
          obj[_key] = item[key]
        } else {
          // 如果不需要直接赋值
          obj[key] = item[key]
        }
      })
      return obj
    })
  }
  const target = transData(soureList)
  console.log(target)

  function getAllAge(sourceList) {
    return sourceList.reduce((a, c) => a + c.age, 0)
  }
  const allAge = getAllAge(soureList)
  console.log(allAge)

</script>